{extend name="light-year/layout/default" /}

{block name="content"}
<div class="card-body">
    <form method="post" action="{:url()}" class="site-form" id="details" onsubmit="saveAdmin( this );return false;">
        <div class="form-group">
            <label>账户：</label>
            <input type="text" class="form-control" name="username" value="{$admin->admin_name}" disabled="disabled" />
            <small class="help-block">
                <i class="mdi mdi-information"></i>
                管理员的账户不可修改！
            </small>
        </div>
        <div class="form-group">
            <label>邮箱:</label>
            <input type="email" class="form-control" name="admin_email" placeholder="输入您的昵称" value="{$admin->admin_email}">
            <small class="help-block">
                <i class="mdi mdi-information"></i>
                请保证您填写的邮箱地址是正确的。
            </small>
        </div>
        <div class="form-group">
            <label>
                头像：
            </label>
            <div>
                <input type="hidden" name="admin_head" value="{$admin->admin_head}" />
                <div id="admin_head">
                    <div id="admin_head_filePicker"><i class="icon-cloud-upload"></i></i> 选择单张图片</div>
                </div>
            </div>
            <small class="help-block">
                <i class="mdi mdi-information"></i>
                管理员的头像设置！
            </small>
        </div>
        <button type="submit" class="btn btn-primary">保存</button>
    </form>
</div>
{/block}

{block name="script"}
{include file="light-year/layout:plugins/webuploader" /}
<script type="text/javascript">
    window.onload = function () {
        closeLayerLoading(closeAllLayer);

        // 图片上传组件
        webUploaderImgs('#admin_head_filePicker', '', '#admin_head', 'input[name=admin_head]', {'img_limit':1, 'single_graph_type':1});

        // 详情图片渲染（使用这种方式，可以共用图片上传限制等功能）
        let detail = JSON.parse('{:html_get_res_from_admin($admin)}');
        if (detail && !isEmpty(detail.admin_head)){
            $('#admin_head').append(webUploaderImgHtml(detail.admin_head, 'input[name=admin_head]', $('#admin_head_filePicker').attr('span-class')));
        }
    }

    function saveAdmin(_this) {
        axios.post( $(_this).attr('action'), $(_this).serialize()).then(function(data){
            if (data.status == 1){
                layerMsg(data.msg, 1, layerJumpTime, 2);
            }
            else layerMsg(data.msg, 5, layerJumpTime);
        }).catch(function(res){
        });
    }
</script>
{/block}